package com.hz.basic.service.impl;

import com.hz.basic.entity.CbExpandResourceEntity;
import com.hz.basic.entity.CbVideoEntity;
import com.hz.common.utils.ResponseData;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.common.utils.PageUtils;
import com.hz.common.utils.Query;

import com.hz.basic.dao.CbTypefaceDao;
import com.hz.basic.entity.CbTypefaceEntity;
import com.hz.basic.service.CbTypefaceService;


@Service("cbTypefaceService")
public class CbTypefaceServiceImpl extends ServiceImpl<CbTypefaceDao, CbTypefaceEntity> implements CbTypefaceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CbTypefaceEntity> page = this.page(
                new Query<CbTypefaceEntity>().getPage(params),
                new QueryWrapper<CbTypefaceEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CbVideoEntity getvideobytid(Long tid) {
        CbTypefaceDao typefaceDao = this.baseMapper;
        return typefaceDao.getvideobytid(tid);
    }

    @Override
    public PageUtils<List<CbTypefaceEntity>> gettypefacesbycondition(String characters, String content, int curpage, int numpage) {
        String[] characterstrs = characters.split(",");
        int total = this.baseMapper.gettypefacestotal(characterstrs, content);
        //不合理的curpage，越界
        if(curpage <= 0 || Math.ceil((double)total/numpage) < curpage)
            return new PageUtils(new ArrayList<CbTypefaceEntity>(),total,numpage,curpage);
        List<CbTypefaceEntity> expandResources = this.baseMapper.gettypefacesbycondition(characterstrs, content, (curpage-1)*numpage,numpage);
        PageUtils<List<CbTypefaceEntity>> page = new PageUtils(expandResources,total,numpage,curpage);
        return page;
    }

}